<style>
    span{
        font-size: 10px;
        opacity: .5;
        color: red;
    }
</style>
<input type="text" name="" id="">
<button>查询</button><br>
<span>时间格式如：xxxx-xx-xx xx:xx:xx</span>
<div></div>

<script src="./time.js"></script>
<script>
    let ipt=document.querySelector('input')
    let btn=document.querySelector('button')
    let div=document.querySelector('div')
    btn.onclick=function(){
        let val=ipt.value
        val=val.replace( /^(?:19|20)[0-9][0-9]-(?:(?:0[1-9])|(?:1[0-2]))-(?:(?:[0-2][1-9])|(?:[1-3][0-1])) (?:(?:[0-2][0-3])|(?:[0-1][0-9])):[0-5][0-9]:[0-5][0-9]$/)
        console.log(getDateDiff(val))
        div.innerText=getDateDiff(val)
    }
    
</script>